﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ProjectRoughWork.Engine.AI
{
    class Seek : AIState
    {
        public Seek(SquadActor initActor)
            : base()
        {
            actor = initActor;
        }

        /// <summary>
        /// Checks if the actor has arrived at the current node in the path
        /// </summary>
        /// <param name="actorPosition">Current Position of the node</param>
        /// <returns>Returns true if arrived, false if the actor hasn't</returns>

        public bool CheckIfArrived(Vector3 actorPosition)
        {
            if ((actorPosition.X < mTarget.X + 20) && (actorPosition.X > mTarget.X - 20) &&
                    (actorPosition.Z < mTarget.Z + 20) && (actorPosition.Z > mTarget.Z - 20)
                )
            {
                return true;
            }

            return false;
        }

        public override void VOnUpdate()
        {
            Vector3 acceleration;
            //mTarget = target;

            acceleration = mTarget - actor.getPosition();
            acceleration.Normalize();

            acceleration *= actor.MaxAcceleration;

            actor.setVelocity(actor.getVelocity() + acceleration);

            EventMoveActor moveEvent = new EventMoveActor(actor.getID(), actor.getPosition() + actor.getVelocity());
            EventManager.GetInstance().VQueueEvent(moveEvent);            
        }

        //Data Members

        SquadActor actor;
    }
}
